﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
using Ccit.OA.MsNotify;
using System.Collections.Generic;
using Ccit.Utils;

namespace Ccit.OA.Notify
{
    public partial class notify_view_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ViewState["Query"] = "";
                ViewState["Type"] = "1";
                if (Session["QryClause"] != null)
                {
                    ViewState["Query"] = Session["QryClause"];
                    Session.Remove("QryClause");
                }
                LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
                CtrInterface.BindDropDown(ref ddlSearch, "NTF_A4", "NTF_A4_10", "NTF_A4_40", true, "", "NTF_A4_30=2 and NTF_A4_9994="+loginUser.UserId+"");
            }
            DataBindn();
        }

        private void DataBindn()
        {            
            NotifyBLL Bll = new NotifyBLL();
            List<MsNotifyMessage> lstMes = Bll.GetViewMes(ViewState["Query"].ToString(), ViewState["Type"].ToString());
            dgMain.DataSource = lstMes;
            dgMain.DataBind();
        }

        protected void dgMain_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string sRecid = dgMain.GetRowValues(e.VisibleIndex, "id").ToString();
            string state = dgMain.GetRowValues(e.VisibleIndex, "state").ToString();
            string content = dgMain.GetRowValues(e.VisibleIndex, "content").ToString();
            string receipt = dgMain.GetRowValues(e.VisibleIndex, "receipt").ToString();
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];             
            if (state == "0")
            {
                if (receipt == "0")
                {
                    e.Row.Cells[0].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + loginUser.UserId + "," + receipt + ")\"><font color=#0000FF>已阅</font></a>";
                }
                else
                {
                    if (content != "")
                    {
                        e.Row.Cells[0].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + loginUser.UserId + "," + receipt + ")\"><font color=#0000FF>已阅已回</font></a>";
                    }
                    else
                    {
                        e.Row.Cells[0].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + loginUser.UserId + "," + receipt + ")\"><font color=#0000FF>已阅未回</font></a>";
                    }
                }
            }
            else
            {
                e.Row.Cells[0].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + loginUser.UserId + "," + receipt + ")\"><font color=red>未阅</font></a>";
            }
        }

        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            ViewState["Query"] = "";
            ViewState["Type"] = "2";
            NotifyBLL Bll = new NotifyBLL();
            if (ddlSearch.SelectedValue != "")
            {
                string QueryId = ddlSearch.SelectedValue;
                MsQueryClass ms = Bll.GetQueryEdit(QueryId);
                ViewState["Query"] = ms.content;
            }
            DataBindn();
        }
    }
}
